package com.appkubes.fintech.common.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author Jiahong Chen
 * @date 2019/10/31
 */
@Data
public class Response<T extends Object> {

    @ApiModelProperty("响应状态码")
    private Integer code;

    @ApiModelProperty("响应消息")
    private String message;

    @ApiModelProperty("响应数据")
    private T data;

    public Response(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Response(ResponseCode responseCode, String message) {
        this.code = responseCode.getCode();
        this.message = message;
    }

    public Response(ResponseCode responseCode, T data) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
        this.data = data;
    }

    public Response(ResponseCode responseCode, String message, T data) {
        this.code = responseCode.getCode();
        this.message = message;
        this.data = data;
    }

    public Response(ResponseCode responseCode) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
    }

    public Response(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(T data) {
        this.code = ResponseCode.SUCCESS.getCode();
        this.message = ResponseCode.SUCCESS.getMessage();
        this.data = data;
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(ResponseCode.SUCCESS, data);
    }

    public static <T> Response<T> success() {
        return new Response<>(ResponseCode.SUCCESS);
    }

    public static <T> Response<T> fail(T data) {
        return new Response<>(ResponseCode.FAIL, data);
    }

    public static <T> Response<T> fail() {
        return new Response<>(ResponseCode.FAIL);
    }

    public static Response fail(String message) {
        return new Response(ResponseCode.FAIL, message);
    }
}
